package edu.java.lectures.lec07.comparable;

import java.util.Arrays;

public class TestReferentTypeComparable {

    public static void main(String[] args) {
	// Segment[] segmentArr = new Segment[] { new Segment(5), new
	// Segment(45),
	// new Segment(3), new Segment(4) };
	// sortSegmentArr(segmentArr);
	// System.out.println(Arrays.toString(segmentArr));

	Apple[] appleArr = new Apple[] { new Apple(5), new Apple(45),
		new Apple(3), new Apple(4) };
	sortAppleArr(appleArr);
	System.out.println(Arrays.toString(appleArr));
    }

    private static void sortAppleArr(Apple[] appleArr) {
	// todo verification
	for (int i = 0; i < (appleArr.length - 1); i++) {
	    for (int j = i + 1; j < (appleArr.length); j++) {
		// obj(i) - obj(j) > 0 => obj(i) > obj(j)
		if (appleArr[i].compareTo(appleArr[j]) > 0) {
		    Apple temp = appleArr[i];
		    appleArr[i] = appleArr[j];
		    appleArr[j] = temp;
		}
	    }
	}
    }

    public static void sortSegmentArr(Segment[] segmentArr) {
	// todo verification
	for (int i = 0; i < (segmentArr.length - 1); i++) {
	    for (int j = i + 1; j < (segmentArr.length); j++) {
		// obj(i) - obj(j) > 0 => obj(i) > obj(j)
		if (segmentArr[i].compareTo(segmentArr[j]) > 0) {
		    Segment temp = segmentArr[i];
		    segmentArr[i] = segmentArr[j];
		    segmentArr[j] = temp;
		}
	    }
	}
    }
}
